﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

using ArcannEngine.Entities;
using ArcannEngine.Render;

namespace ArcannEngine.Components
{
    class TerrainCollisionComponent : Component
    {
        // Wartosc mowiaca ile nalezy przesunac obiekt powyzej mapy
        // zeby byl poprawnie wyswietlany
        public float baseOffset;
        public float floatOffset;
        Entity ParentEntity;

        public TerrainCollisionComponent(Entity ParentEntity, float offset)
            : base(ParentEntity)
        {
            Initialize();
            this.ParentEntity = ParentEntity;
            this.baseOffset = offset;
            this.floatOffset = offset;
        }

        protected override string GetName()
        {
            return "TerrainCollision";
        }

        public override void Update(GameTime gameTime)
        {
            if (ParentEntity.Manager.HeightMapInfo.IsOnHeightmap(ParentEntity.position))
            {
                /*if (ParentEntity.position.Y + floatOffset < ParentEntity.Manager.HeightMapInfo.GetHeight(ParentEntity.position) + baseOffset)
                {
                    floatOffset = baseOffset;
                }*/
                ParentEntity.position.Y = ParentEntity.Manager.HeightMapInfo.GetHeight(ParentEntity.position) +
                    floatOffset;
            }
        }
    }
}
